﻿using Face8280WebSocketServer.DB;
using Face8280WebSocketServer.DB.Access;
using Face8280WebSocketServer.DB.Access.APIResult;
using Face8280WebSocketServer.DB.Device;
using Face8280WebSocketServer.DTO;
using Face8280WebSocketServer.Model.People;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Face8280WebSocketServer.Interface
{
    /// <summary>
    /// 设备门禁权限服务
    /// </summary>
    public interface IDeviceAccessService : IBaseService
    {

        /// <summary>
        /// 根据条件查询门禁权限
        /// </summary>
        /// <param name="sn"></param>
        /// <param name="name"></param>
        /// <param name="remote"></param>
        /// <returns></returns>
        PageResult<DeviceAccessDetail_DTO_Mini> GetList(DeviceAccessDetail_DTO queryPar, DTO.BasePageParameter pagePar);

        /// <summary>
        /// 根据权限ID获取权限详情
        /// </summary>
        /// <returns></returns>
        DeviceAccessDetail_DTO GetAccessDetail(int iAccessID);


        /// <summary>
        /// 批量授权
        /// </summary>
        /// <returns></returns>
        Task Add(List<int> oDevicesIDs, List<int> oPeopleIDs, int iAccessType, FacePeopleAccessDetail detail);

        public void Add(FacePeopleAccessDetail pAccess);
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="sn"></param>
        /// <returns></returns>
        void Delete(List<int> iAccessID);

        /// <summary>
        /// 更新单个开门权限
        /// </summary>
        Task Update(FacePeopleAccessDetail detail);

        /// <summary>
        /// 清空所有开门权限
        /// </summary>
        void ClearAccess();

        /// <summary>
        /// 获取根据门ID获取指定数量的需要同步的权限
        /// </summary>
        /// <param name="doorID"></param>
        /// <returns></returns>
        List<APIResult_DevicePeopleModel> GetSyncAccessbyDoorID(string SN, int doorID, int iLimit);

        /// <summary>
        /// 保存设备拉取人员的上传状态，并处理失败的人员信息
        /// </summary>
        /// <param name="failNumber"></param>
        /// <param name="peopleInfos"></param>
        void SavePeopleAccessUploadResult(string sSN, int failNumber, List<APIRequest_PeopleInfo> peopleInfos);


        /// <summary>
        /// 根据门ID获取待删除的权限
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="iD"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        List<APIResult_PeopleID> GetDeleteAccessbyDoorID(string SN, int DoorID, int limit);

        /// <summary>
        /// 保存删除设备人员的操作结果
        /// </summary>
        /// <param name="SN"></param>
        /// <param name="deleteAll"></param>
        Task SaveDeleteAccessUploadResult(string SN, int deleteAll);

        /// <summary>
        /// 对所有人进行权限操作的接口
        /// </summary>
        /// <param name="deviceIDs"></param>
        /// <param name="accessType"></param>
        /// <param name="accessDetail"></param>
        /// <returns></returns>
        Task Add_ALL(List<int> deviceIDs, int accessType, FacePeopleAccessDetail accessDetail);

        /// <summary>
        /// 更新设备权限统计数
        /// </summary>
        /// <param name="hsDeviceID"></param>
        /// <returns></returns>
        Task UpdateDeviceAccessTotal(IEnumerable<int> hsDeviceID);

        /// <summary>
        /// 使指定的权限重新上传
        /// </summary>
        /// <param name="accessIDs"></param>
        void Reupload(List<int> accessIDs);

        /// <summary>
        /// 使全部的权限重新上传
        /// </summary>
        void ReuploadAll();

        public void SavePeopleAccessUploadResult(string sSn, uint code, long repeatCode, int error);

        public void Delete(string sn, List<uint> codes);
    }
}
